package com.java.learn.hive;

import org.apache.hadoop.hive.ql.exec.UDF;

/**
 * @Copyright: Shanghai Definesys Company.All rights reserved.
 * @Description: hive的自定义函数
 * @author: chuhaitao
 * @since: 2019/3/17 22:12
 * @history: 1.2019/3/17 created by chuhaitao
 */
public class IpToLong extends UDF {

    public Long evaluate(String ip) {
        String[] fv = ip.split("[.]");
        Long ipNum = 0L;
        for (int i = 0; i < fv.length; i++) {
            ipNum = Long.parseLong(fv[i]) | ipNum << 8L;
        }

        return ipNum;
    }


}
